﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Document_Management
{
    public partial class frmManagerSearch : Form
    {
        TextBox tx;

        static string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["庫存管理"].ConnectionString;
        SqlConnection con = new SqlConnection(connectionString);

        public frmManagerSearch(TextBox tx)
        {
            InitializeComponent();
            this.tx = tx;
        }

        private void btn_使用者_查詢_Click(object sender, EventArgs e)
        {
           
            try
            {
                con.Open();
                string sp_search = "sp_管理者_查詢";
                SqlDataAdapter cmd = new SqlDataAdapter(sp_search,con);
                cmd.SelectCommand.CommandType = CommandType.StoredProcedure;
                if (txt姓名或代號.Text != "") cmd.SelectCommand.Parameters.AddWithValue("@姓名或代號", txt姓名或代號.Text);
                DataTable dt = new DataTable();
                cmd.Fill(dt);
                dataGV管理者.DataSource = dt;
                PublicClass.setRowNumber(dataGV管理者);
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void frmManagerSearch_Load(object sender, EventArgs e)
        {
            //SqlConnection con = new SqlConnection();
            try
            {
                con.Open();
                string sp_search = "sp_管理者_查詢";
                SqlDataAdapter cmd = new SqlDataAdapter(sp_search, con);
                cmd.SelectCommand.CommandType = CommandType.StoredProcedure;
               // if (txt姓名或代號.Text != "") cmd.SelectCommand.Parameters.AddWithValue("@姓名或代號", txt姓名或代號.Text);
                DataTable dt = new DataTable();
                cmd.Fill(dt);
                dataGV管理者.DataSource = dt;
                PublicClass.setRowNumber(dataGV管理者);
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            int r = dataGV管理者.CurrentCell.RowIndex;
            string text = dataGV管理者.Rows[r].Cells[0].Value.ToString();
            tx.Text = text;
            this.Close();
        }

        private void dataGV管理者_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dataGV管理者);
        }
    }
}
